<item>
  <title>WCF and eBay</title>
  <link>http://contoso.com/rss</link>
  <pubDate>Thu, 12 Oct 2006 16:20:00 Z</pubDate>
  <guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:820210</guid>
  <comments>http://contoso.com/test</comments>
  <description>
    &lt;P&gt;eBay provides a very rich, though very complicated, &lt;A class="" href="http://contoso.com/developercenter/soap" mce_href="http://contoso.com/developercenter/soap"&gt;SOAP API&lt;/A&gt;.&amp;nbsp; It is possible to use WCF with eBay, but it takes a few tricks.&amp;nbsp; First read &lt;A class="" href="http://contoso.com/2006/04/18/21943.aspx" mce_href="http://contoso.com/2006/04/18/21943.aspx"&gt;this&lt;/A&gt; article.&amp;nbsp; I'll wait.&amp;nbsp; Ok, since that didn't scare you away I'll continue.&amp;nbsp; Everything there is still necessary except the custom message encoder for removing the quotes around the content type.&amp;nbsp; In fact the basicHttpBinding produced by svcutil.exe is just fine, though bumping up some of the quotas (&lt;FONT size=2&gt;maxNameTableCharCount, &lt;FONT size=2&gt;maxBufferSize, &lt;FONT size=2&gt;maxReceivedMessageSize)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;might not hurt.&amp;nbsp; Now calling GeteBayOfficialTime just works, but graduating to say GetItem, there's another problem.&amp;nbsp; GetItem returns a GetItemResponseType which derives from AbstractResponseType.&amp;nbsp; After successfully calling GetItemResponseType, all the fields it inherits are correctly populated but the fields it defines haven't been.&amp;nbsp; Looking at the response on the wire, those fields are there, for some reason they weren't deserialized.&amp;nbsp; The problem is eBay defined the schema for AbstractResponseType with an xs:any, so the code generated for this type includes an array of XmlElements with the XmlAny attribute:&lt;/P&gt;&lt;FONT size=2&gt;
    &lt;P&gt;[System.Xml.Serialization.XmlAnyAttribute(Order=12)] &lt;/P&gt;
    &lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;FONT size=2&gt; System.Xml.XmlElement[] Any&lt;/FONT&gt;&lt;/P&gt;
    &lt;P&gt;&lt;FONT size=2&gt;When the response from eBay arrives the XmlSerializer happily begins populating all the fields in AbstractResponseType and anything it doesn't recognize gets put into Any.&amp;nbsp; Now when it's time to populate the fields defined in GetItemResponseType there's no xml left.&amp;nbsp; Given this knowledge it's an easy fix, but unfortunately it involves manually editing the generated proxy.&amp;nbsp; All that's necessary is to change the XmlAnyAttribute to an XmlIgnoreAttribute.&amp;nbsp; Now upon receiving the response, the XmlSerializer "saves" any elements that don't map to AbstractResponseType and uses them to populate GetItemResponseType.&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://contoso.com/images" width="1" height="1"&gt;
  </description>
</item>
